<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>数组最大值</title>
</head>

<body>

	<p> 数组最大值</p>
	<p id="demo"></p>
	<script>

		function max(arr) {
			var max = arr[0]

			// for (var val of arr) {
			// 	if (max < val) {
			// 		max = val;
			// 	}
			// }


			for(var i = 0 ; i < arr.length ; i++){
				if (max < arr[i]) {
					max = arr[i];
				}
			}
			return max;
		}
		var arr = [2,1,3,0,19];
		console.log('s1', max(arr));
	</script>

</body>

</html>